package com.example.action;

import com.example.bean.Order;
import com.example.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/saveOrder")
public class SaveOrderServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String address = req.getParameter("address");
        String receptor = req.getParameter("receptor");
        String telephone = req.getParameter("telephone");
        String oid = req.getParameter("oid");
        OrderService service = new OrderService();
        Order order = service.selectOrderByOid(oid);
        order.setAddress(address);
        order.setName(receptor);
        order.setTelephone(telephone);
        int n = service.updateOrder(order);
        if (n == 1) {
            resp.sendRedirect(req.getContextPath() + "/selectOrder");
        }
    }
}
